<!-- role select -->
<template>
  <el-select class="c-select" v-model="selectValue" :placeholder="placeholder" :size="size" :disabled="disabled"
             :clearable="clearable" :filterable="filterable" @change="handleChange">
    <el-option v-for="item in options" :key="item.value" :label="item.name" :value="item.value" :disabled="item.disabled">
    </el-option>
  </el-select>
</template>

<script>
import { GetRoleAllList } from '@/api/system'
export default {
  name: '',
  data () {
    return {
      selectValue: '',
      loading: false,
      options: []
    }
  },
  props: {
    value: {
      type: String,
      default: ''
    },
    placeholder: {
      type: String,
      default: '请选择角色'
    },
    clearable: {
      type: Boolean,
      default: true
    },
    filterable: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    size: {
      type: String,
      default: ''
    },
    styles: {
      type: Object,
      default: () => { }
    }
  },
  created () {
    this.remoteMethod()
  },
  mounted () {
    this.selectValue = this.value
  },
  methods: {
    handleChange (value) {
      const returnVal = typeof value === 'string' ? value : value.toString()
      this.$emit('input', returnVal)
      this.$emit('change', returnVal)
    },
    remoteMethod () {
      GetRoleAllList().then(res => {
        res.data.forEach(element => {
          const item = {
            value: element.id.toString(),
            name: element.name
          }
          this.options.push(item)
        })
      })
    }
  }
}

</script>
